﻿using Oliving.Common.SheBei;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChargingSystem4.Common
{
    public class RwRecord
    {
        public int 禁止启动 { get; set; }
        public int 预加压时间 { get; set; }
        public int 加压时间 { get; set; }
        public int 禁预热方式止启动 { get; set; }
        public int 预热时间 { get; set; }

        //===================================================
        public int 冷却时间1 { get; set; }
        public int 焊接方式 { get; set; }
        public int 递增递减 { get; set; }
        public int 递增时间 { get; set; }
        public int 焊接时间 { get; set; }

        //===================================================

        public int 递减时间 { get; set; }
        public int 冷却时间2 { get; set; }
        public int 焊接脉冲数 { get; set; }
        public int 冷却时间3 { get; set; }
        public int 回火方式 { get; set; }

        public int 回火时间 { get; set; }
        public int 维持时间 { get; set; }
        public int 休止时间 { get; set; }
        public int 连续_单点 { get; set; }
        public int 断开时间 { get; set; }


        //===================================================
        public int 脉冲启动 { get; set; }
        public int 接触器延时 { get; set; }
        public int 未定义2 { get; set; }
        public int 预热电流 { get; set; }
        public int 起始电流 { get; set; }
        public int 焊接电流 { get; set; }
        public int 终止电流 { get; set; }
        public int 回火电流 { get; set; }
        public int 测量延时 { get; set; }
        public int 规范工作模式 { get; set; }

        //===================================================

        public int 未定义4 { get; set; }
        public int 未定义5 { get; set; }
        public int 预热监控 { get; set; }
        public int 焊接监控 { get; set; }
        public int 回火监控 { get; set; }
        public int 预热参考值 { get; set; }
        public int I1超限值 { get; set; }
        public int I1许可欠限值 { get; set; }
        public int I1报警欠限值 { get; set; }
        public int 焊接参考值 { get; set; }

      
        //===================================================


        public int I2超限值 { get; set; }
        public int I2许可欠限值 { get; set; }
        public int I2报警欠限值 { get; set; }
        public int 回火参考值 { get; set; }
        public int I3超限值 { get; set; }
        public int I3许可欠限值 { get; set; }
        public int I3报警欠限值 { get; set; }
        public int 连欠限点数 { get; set; }
        public int 补焊控制 { get; set; }
        public int 连补焊点数 { get; set; }

        //===================================================


        public int 未定义6 { get; set; }
        public int 未定义7 { get; set; }
        public int 可编程输出A { get; set; }
        public int A断开1时间 { get; set; }
        public int A闭合1时间 { get; set; }
        public int A断开2时间 { get; set; }
        public int A闭合2时间 { get; set; }
        public int A断开3时间 { get; set; }
        public int A闭合3时间 { get; set; }
        public int 未定义8 { get; set; }
        public int 电流步增开关 { get; set; }
        public int 电极修磨开关 { get; set; }


    }

    #region MyRegion

    //1	禁止启动 禁止启动    MODBUS RTU(Zero-based Addressing)  6x	1		16-bit Unsigned     RS485_Data[1]
    //2	预加压时间 预加压时间   MODBUS RTU(Zero-based Addressing)  6x	2		16-bit Unsigned     RS485_Data[2]
    //3	加压时间 加压时间    MODBUS RTU(Zero-based Addressing)  6x	3		16-bit Unsigned     RS485_Data[3]
    //4	预热方式 预热方式    MODBUS RTU(Zero-based Addressing)  6x	4		16-bit Unsigned     RS485_Data[4]
    //5	预热时间 预热时间    MODBUS RTU(Zero-based Addressing)  6x	5		16-bit Unsigned     RS485_Data[5]
    //6	冷却时间1 冷却时间1   MODBUS RTU(Zero-based Addressing)  6x	6		16-bit Unsigned     RS485_Data[6]
    //7	焊接方式 焊接方式    MODBUS RTU(Zero-based Addressing)  6x	7		16-bit Unsigned     RS485_Data[7]
    //8	递增递减 递增递减    MODBUS RTU(Zero-based Addressing)  6x	8		16-bit Unsigned     RS485_Data[8]
    //9	递增时间 递增时间    MODBUS RTU(Zero-based Addressing)  6x	9		16-bit Unsigned     RS485_Data[9]
    //10	焊接时间 焊接时间    MODBUS RTU(Zero-based Addressing)  6x	10		16-bit Unsigned     RS485_Data[10]
    //11	递减时间 递减时间    MODBUS RTU(Zero-based Addressing)  6x	11		16-bit Unsigned     RS485_Data[11]
    //12	冷却时间2 冷却时间2   MODBUS RTU(Zero-based Addressing)  6x	12		16-bit Unsigned     RS485_Data[12]
    //13	焊接脉冲数 焊接脉冲数   MODBUS RTU(Zero-based Addressing)  6x	13		16-bit Unsigned     RS485_Data[13]
    //14	冷却时间3 冷却时间3   MODBUS RTU(Zero-based Addressing)  6x	14		16-bit Unsigned     RS485_Data[14]
    //15	回火方式 回火方式    MODBUS RTU(Zero-based Addressing)  6x	15		16-bit Unsigned     RS485_Data[15]
    //16	回火时间 回火时间    MODBUS RTU(Zero-based Addressing)  6x	16		16-bit Unsigned     RS485_Data[16]
    //17	维持时间 维持时间    MODBUS RTU(Zero-based Addressing)  6x	17		16-bit Unsigned     RS485_Data[17]
    //18	休止时间 休止时间    MODBUS RTU(Zero-based Addressing)  6x	18		16-bit Unsigned     RS485_Data[18]
    //19	连续/单点 连续/单点 MODBUS RTU(Zero-based Addressing)  6x	19		16-bit Unsigned     RS485_Data[19]
    //20	断开时间 断开时间    MODBUS RTU(Zero-based Addressing)  6x	20		16-bit Unsigned     RS485_Data[20]
    //21	脉冲启动 脉冲启动    MODBUS RTU(Zero-based Addressing)  6x	21		16-bit Unsigned     RS485_Data[21]
    //22	接触器延时 接触器延时   MODBUS RTU(Zero-based Addressing)  6x	22		16-bit Unsigned     RS485_Data[22]
    //23	未定义2 未定义2    MODBUS RTU(Zero-based Addressing)  6x	23		16-bit Unsigned     RS485_Data[23]
    //24	预热电流 预热电流    MODBUS RTU(Zero-based Addressing)  6x	24		16-bit Unsigned     RS485_Data[24]
    //25	起始电流 起始电流    MODBUS RTU(Zero-based Addressing)  6x	25		16-bit Unsigned     RS485_Data[25]
    //26	焊接电流 焊接电流    MODBUS RTU(Zero-based Addressing)  6x	26		16-bit Unsigned     RS485_Data[26]
    //27	终止电流 终止电流    MODBUS RTU(Zero-based Addressing)  6x	27		16-bit Unsigned     RS485_Data[27]
    //28	回火电流 回火电流    MODBUS RTU(Zero-based Addressing)  6x	28		16-bit Unsigned     RS485_Data[28]
    //29	测量延时 测量延时    MODBUS RTU(Zero-based Addressing)  6x	29		16-bit Unsigned     RS485_Data[29]
    //30	规范工作模式 规范工作模式  MODBUS RTU(Zero-based Addressing)  6x	30		16-bit Unsigned     RS485_Data[30]
    //31	未定义4 未定义4    MODBUS RTU(Zero-based Addressing)  6x	31		16-bit Unsigned     RS485_Data[31]
    //32	未定义5 未定义5    MODBUS RTU(Zero-based Addressing)  6x	32		16-bit Unsigned     RS485_Data[32]
    //33	预热监控 预热监控    MODBUS RTU(Zero-based Addressing)  6x	33		16-bit Unsigned     RS485_Data[33]
    //34	焊接监控 焊接监控    MODBUS RTU(Zero-based Addressing)  6x	34		16-bit Unsigned     RS485_Data[34]
    //35	回火监控 回火监控    MODBUS RTU(Zero-based Addressing)  6x	35		16-bit Unsigned     RS485_Data[35]
    //36	预热参考值 预热参考值   MODBUS RTU(Zero-based Addressing)  6x	36		16-bit Unsigned     RS485_Data[36]
    //37	I1超限值 I1超限值   MODBUS RTU(Zero-based Addressing)  6x	37		16-bit Unsigned     RS485_Data[37]
    //38	I1许可欠限值 I1许可欠限值 MODBUS RTU(Zero-based Addressing)  6x	38		16-bit Unsigned     RS485_Data[38]
    //39	I1报警欠限值 I1报警欠限值 MODBUS RTU(Zero-based Addressing)  6x	39		16-bit Unsigned     RS485_Data[39]
    //40	焊接参考值 焊接参考值   MODBUS RTU(Zero-based Addressing)  6x	40		16-bit Unsigned     RS485_Data[40]
    //41	I2超限值 I2超限值   MODBUS RTU(Zero-based Addressing)  6x	41		16-bit Unsigned     RS485_Data[41]
    //42	I2许可欠限值 I2许可欠限值 MODBUS RTU(Zero-based Addressing)  6x	42		16-bit Unsigned     RS485_Data[42]
    //43	I2报警欠限值 I2报警欠限值 MODBUS RTU(Zero-based Addressing)  6x	43		16-bit Unsigned     RS485_Data[43]
    //44	回火参考值 回火参考值   MODBUS RTU(Zero-based Addressing)  6x	44		16-bit Unsigned     RS485_Data[44]
    //45	I3超限值 I3超限值   MODBUS RTU(Zero-based Addressing)  6x	45		16-bit Unsigned     RS485_Data[45]
    //46	I3许可欠限值 I3许可欠限值 MODBUS RTU(Zero-based Addressing)  6x	46		16-bit Unsigned     RS485_Data[46]
    //47	I3报警欠限值 I3报警欠限值 MODBUS RTU(Zero-based Addressing)  6x	47		16-bit Unsigned     RS485_Data[47]
    //48	连欠限点数 连欠限点数   MODBUS RTU(Zero-based Addressing)  6x	48		16-bit Unsigned     RS485_Data[48]
    //49	补焊控制 补焊控制    MODBUS RTU(Zero-based Addressing)  6x	49		16-bit Unsigned     RS485_Data[49]
    //50	连补焊点数 连补焊点数   MODBUS RTU(Zero-based Addressing)  6x	50		16-bit Unsigned     RS485_Data[50]
    //51	未定义6 未定义6    MODBUS RTU(Zero-based Addressing)  6x	51		16-bit Unsigned     RS485_Data[51]
    //52	未定义7 未定义7    MODBUS RTU(Zero-based Addressing)  6x	52		16-bit Unsigned     RS485_Data[52]
    //53	可编程输出A 可编程输出A  MODBUS RTU(Zero-based Addressing)  6x	53		16-bit Unsigned     RS485_Data[53]
    //54	A断开1时间 A断开1时间  MODBUS RTU(Zero-based Addressing)  6x	54		16-bit Unsigned     RS485_Data[54]
    //55	A闭合1时间 A闭合1时间  MODBUS RTU(Zero-based Addressing)  6x	55		16-bit Unsigned     RS485_Data[55]
    //56	A断开2时间 A断开2时间  MODBUS RTU(Zero-based Addressing)  6x	56		16-bit Unsigned     RS485_Data[56]
    //57	A闭合2时间 A闭合2时间  MODBUS RTU(Zero-based Addressing)  6x	57		16-bit Unsigned     RS485_Data[57]
    //58	A断开3时间 A断开3时间  MODBUS RTU(Zero-based Addressing)  6x	58		16-bit Unsigned     RS485_Data[58]
    //59	A闭合3时间 A闭合3时间  MODBUS RTU(Zero-based Addressing)  6x	59		16-bit Unsigned     RS485_Data[59]
    //60	未定义8 未定义8    MODBUS RTU(Zero-based Addressing)  6x	60		16-bit Unsigned     RS485_Data[60]
    //61	电流步增开关 电流步增开关  MODBUS RTU(Zero-based Addressing)  6x	61		16-bit Unsigned     RS485_Data[61]
    //62	电极修磨开关 电极修磨开关  MODBUS RTU(Zero-based Addressing)  6x	62		16-bit Unsigned     RS485_Data[62]

    #endregion

    public static class RwRecordHelper
    {
        public static RwRecord Convert(byte[] allByte)
        {
            RwRecord rwRecord = new RwRecord();
             
            #region MyRegion

            rwRecord.禁止启动 = GetConvert(allByte, 1);
            rwRecord.预加压时间 = GetConvert(allByte, 2);
            rwRecord.加压时间 = GetConvert(allByte, 3);
            rwRecord.禁预热方式止启动 = GetConvert(allByte, 4);
            rwRecord.预热时间 = GetConvert(allByte, 5);


            //===================================================
            rwRecord.冷却时间1 = GetConvert(allByte, 6);
            rwRecord.焊接方式 = GetConvert(allByte, 7);
            rwRecord.递增递减 = GetConvert(allByte, 8);
            rwRecord.递增时间 = GetConvert(allByte, 9);
            rwRecord.焊接时间 = GetConvert(allByte, 10);

            //===================================================

            rwRecord.递减时间 = GetConvert(allByte, 11);
            rwRecord.冷却时间2 = GetConvert(allByte, 12);
            rwRecord.焊接脉冲数 = GetConvert(allByte, 13);
            rwRecord.冷却时间3 = GetConvert(allByte, 14);
            rwRecord.回火方式 = GetConvert(allByte, 15);

            rwRecord.回火时间 = GetConvert(allByte, 16);
            rwRecord.维持时间 = GetConvert(allByte, 17);
            rwRecord.休止时间 = GetConvert(allByte, 18);
            rwRecord.连续_单点 = GetConvert(allByte, 19);
            rwRecord.断开时间 = GetConvert(allByte, 20);


            //===================================================
            rwRecord.脉冲启动 = rwRecord.断开时间 = GetConvert(allByte, 21);
            rwRecord.接触器延时 = rwRecord.断开时间 = GetConvert(allByte, 22);
            rwRecord.未定义2 = rwRecord.断开时间 = GetConvert(allByte, 23);
            rwRecord.预热电流 = rwRecord.断开时间 = GetConvert(allByte, 24);
            rwRecord.起始电流 = rwRecord.断开时间 = GetConvert(allByte, 25);
            rwRecord.焊接电流 = rwRecord.断开时间 = GetConvert(allByte, 26);
            rwRecord.终止电流 = rwRecord.断开时间 = GetConvert(allByte, 27);
            rwRecord.回火电流 = rwRecord.断开时间 = GetConvert(allByte, 28);
            rwRecord.测量延时 = rwRecord.断开时间 = GetConvert(allByte, 29);
            rwRecord.规范工作模式 = rwRecord.断开时间 = GetConvert(allByte, 30);

            //===================================================

            rwRecord.未定义4 = GetConvert(allByte, 31);
            rwRecord.未定义5 = GetConvert(allByte, 32);
            rwRecord.预热监控 = GetConvert(allByte, 33);
            rwRecord.焊接监控 = GetConvert(allByte, 34);
            rwRecord.回火监控 = GetConvert(allByte, 35);
            rwRecord.预热参考值 = GetConvert(allByte, 36);
            rwRecord.I1超限值 = GetConvert(allByte, 37);
            rwRecord.I1许可欠限值 = GetConvert(allByte, 38);
            rwRecord.I1报警欠限值 = GetConvert(allByte, 39);
            rwRecord.焊接参考值 = GetConvert(allByte, 40);



            //===================================================


            rwRecord.I2超限值 = GetConvert(allByte, 41);
            rwRecord.I2许可欠限值 = GetConvert(allByte, 42);
            rwRecord.I2报警欠限值 = GetConvert(allByte, 43);
            rwRecord.回火参考值 = GetConvert(allByte, 44);
            rwRecord.I3超限值 = GetConvert(allByte, 45);
            rwRecord.I3许可欠限值 = GetConvert(allByte, 46);
            rwRecord.I3报警欠限值 = GetConvert(allByte, 47);
            rwRecord.连欠限点数 = GetConvert(allByte, 48);
            rwRecord.补焊控制 = GetConvert(allByte, 49);
            rwRecord.连补焊点数 = GetConvert(allByte, 50); ;

            //===================================================


            rwRecord.未定义6 = GetConvert(allByte, 51);
            rwRecord.未定义7 = GetConvert(allByte, 52);
            rwRecord.可编程输出A = GetConvert(allByte, 53);
            rwRecord.A断开1时间 = GetConvert(allByte, 54);
            rwRecord.A闭合1时间 = GetConvert(allByte, 55);
            rwRecord.A断开2时间 = GetConvert(allByte, 56);
            rwRecord.A闭合2时间 = GetConvert(allByte, 57);
            rwRecord.A断开3时间 = GetConvert(allByte, 58);
            rwRecord.A闭合3时间 = GetConvert(allByte, 59);
            rwRecord.未定义8 = GetConvert(allByte, 60);
            rwRecord.电流步增开关 = GetConvert(allByte, 61);
            rwRecord.电极修磨开关 = GetConvert(allByte, 62);



            #endregion


            return rwRecord;
        }


        public static int GetConvert(byte[] allByte, int index)
        {
            if (allByte.Length >= (index + 2))
            {
                byte[] beginData = new byte[2];

                int myIndex = (index - 1) * 2;

                beginData[0] = allByte[myIndex];
                beginData[1] = allByte[myIndex + 1];

                int intBegin = ModbusHelper.ByteToInt(beginData);
                return intBegin;
            }
            else
            {
                return 0;
            }
        }

    }


}
